package core

class LocalityController {



	static layout = 'country'

	def createLoc() {
	}

	def list1() {
		def max = params.long('max')?:10
		def start = params.long('start')?:0
		[localitis:Locality.list(max: max, offset:start ),max:max, start:start ]
	}
	def update() {
		def locality =  Locality.get(params.long('id'))
		locality.properties = params
		if(locality.save()) {
			flash.notice = "Locality: ${locality.name} was updated"
			redirect action:'index'
		}
		else {
			flash.error = "Locality:  failed to be update"
			render(view:'editLoc',model:[locality: locality])
		}
	}

	def editLoc() {
		[locality: Locality.get(params.long('id'))]
	}

	def deleteLoc() {
		def locality =  Locality.get(params.id)

		locality.delete()
		redirect(action:'index')
	}

	def save() {
		def locality = new Locality(params)

		if (locality.save()) {
			flash.notice = "Locality ${locality.name}: is saved successfuly"
			redirect(action:'index')
		} else {
			flash.error = "Locality ${locality.name}: Failed to save"
			render view:'createLoc', model:[locality:locality]
		}
	}

	def index() {

		//		def max = params.long('max')?:10
		//		def start = params.long('start')?:0
		//		[localitis:Locality.list(max: max, offset:start ),max:max, start:start ]


	}



	def show() {

		[locality: Locality.get(params.long('id'))]
	}
}
